package com.ewanghuiju.app.ui.resale.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.pm.ActivityInfo;
import android.graphics.Paint;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.App;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.app.ForegroundCallbacks;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.resale.ResaleShopDetailsContract;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.model.bean.response.AddressListResponBean;
import com.ewanghuiju.app.model.bean.response.PingjiaListResponBean;
import com.ewanghuiju.app.model.bean.response.PintuanGoodsSpecsResponBean;
import com.ewanghuiju.app.model.bean.response.PintuanOnlineListResponBean;
import com.ewanghuiju.app.model.bean.response.PintuanShopListResponBean;
import com.ewanghuiju.app.model.bean.response.ShareResponBean;
import com.ewanghuiju.app.presenter.resale.ResaleShopDetailsPresenter;
import com.ewanghuiju.app.test.bean.PintuanHomeBannerBean;
import com.ewanghuiju.app.ui.home.activity.SearchShopResultActivity;
import com.ewanghuiju.app.ui.main.activity.MainActivity;
import com.ewanghuiju.app.ui.my.activity.WalletRechargeActivity;
import com.ewanghuiju.app.ui.pintuan.activity.PintuanPingjiaActivity;
import com.ewanghuiju.app.ui.pintuan.activity.PintuanSureOrderActivity;
import com.ewanghuiju.app.ui.pintuan.adapter.PintuanShopDetailsAdapter;
import com.ewanghuiju.app.ui.pintuan.adapter.PintuanShopDetailsPjAdapter;
import com.ewanghuiju.app.ui.pintuan.adapter.pictureselector.GlideEngine;
import com.ewanghuiju.app.ui.web.MyWebviewActivity;
import com.ewanghuiju.app.util.ClipboardUtils;
import com.ewanghuiju.app.util.LoadingDialogUtils;
import com.ewanghuiju.app.util.PermissionUtil;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.StringUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.ewanghuiju.app.widget.popupwindow.CommonSearchPopup;
import com.ewanghuiju.app.widget.popupwindow.CustomBasePopup;
import com.ewanghuiju.app.widget.popupwindow.PintuanBuyCantuanPopup;
import com.ewanghuiju.app.widget.popupwindow.PintuanFuwuPopup;
import com.ewanghuiju.app.widget.popupwindow.PintuanYoufeiPopup;
import com.ewanghuiju.app.widget.popupwindow.PopupItemClickCallback;
import com.ewanghuiju.app.widget.popupwindow.ShareShopPopup;
import com.ewanghuiju.app.widget.popupwindow.ToGroupleadPopup;
import com.gyf.immersionbar.ImmersionBar;
import com.luck.picture.lib.PictureMediaScannerConnection;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.DateUtils;
import com.luck.picture.lib.tools.PictureFileUtils;
import com.luck.picture.lib.tools.SdkVersionUtils;
import com.luck.picture.lib.tools.ToastUtils;
import com.luck.picture.lib.tools.ValueOf;
import com.muddzdev.styleabletoast.StyleableToast;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.stx.xhb.androidx.XBanner;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import androidx.cardview.widget.CardView;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 转售商品详情
 * @time 2020/2/18
 */
public class ResaleShopDetailsActivity extends BaseActivity<ResaleShopDetailsPresenter> implements ResaleShopDetailsContract.View, ForegroundCallbacks.Listener {

    @BindView(R.id.roll_view_pager)
    XBanner rollViewPager;
    @BindView(R.id.nsv_view)
    NestedScrollView nsvView;
    @BindView(R.id.now_price)
    TextView nowPrice;
    @BindView(R.id.yuan_price)
    TextView yuanPrice;
    @BindView(R.id.tv_sale)
    TextView tvSale;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.layout_top)
    LinearLayout layoutTop;
    @BindView(R.id.tv_look_pingjia_more)
    TextView tvLookPingjiaMore;
    @BindView(R.id.card_view_pingjia)
    CardView cardViewPingjia;
    @BindView(R.id.top_view)
    View topView;
    @BindView(R.id.iv_collect)
    ImageView ivCollect;
    @BindView(R.id.iv_kefu)
    ImageView ivKefu;
    @BindView(R.id.tv_share_zhuan)
    TextView tvShareZhuan;
    @BindView(R.id.tv_kaituan_zhuan)
    TextView tvKaituanZhuan;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.iv_to_top)
    ImageView ivToTop;
    //评价列表
    @BindView(R.id.recyclerview_pj)
    RecyclerView recyclerviewPj;
    @BindView(R.id.recyleview_details)
    RecyclerView recyleviewDetails;

    private PintuanShopListResponBean pintuanShopListResponBean;
    private PintuanShopListResponBean mPintuanShopListResponBean;
    private Animation showAnimation, dismissAnimation;

    private List<PintuanGoodsSpecsResponBean> pintuanGoodsSpecsResponBeanList;

    private String selectedSpace;
    private String mSelectedPrice;
    //当前团号
    private String group_id = "";
    private int shopId = -1;
    private int search_type;

    private List<PintuanOnlineListResponBean> mPintuanOnlineListResponBean;

    private CommonSearchPopup commonSearchPopup;

    private CustomBasePopup customBasePopup;

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_resale_shop_details;
    }

    @Override
    protected void initEventAndData() {
        // 注册监听
        ForegroundCallbacks.get(App.getInstance()).addListener(this);
        shopId = getIntent().getIntExtra(Constants.PINTUAN_SHOP_ID, -1);
        shopId = 335;
        search_type = getIntent().getIntExtra(Constants.PINTUAN_SEARCH_TYPE, -1);
//        int userYes = getIntent().getIntExtra(Constants.PINTUAN_USER_YES, 0);
//        if (search_type == 2) {
//            mPintuanShopListResponBean = (PintuanShopListResponBean) getIntent().getSerializableExtra(Constants.PINTUAN_SEARCH_MOUDE);
//            cardViewCantuan.setVisibility(View.GONE);
//            if (userYes == 1) {
//                tvKaituanZhuan.setText("已参团");
//                tvKaituanZhuan.setBackgroundResource(R.drawable.corner_999_50);
//                tvKaituanZhuan.setClickable(false);
//            } else {
//                tvKaituanZhuan.setText("去参团");
//                tvKaituanZhuan.setBackgroundResource(R.drawable.corner_primary_button_50);
//                tvKaituanZhuan.setClickable(true);
//            }
//        }
        if (shopId == -1) {
            StyleableToast.makeText(mContext, "获取商品失败", Toast.LENGTH_SHORT, R.style.mytoast).show();
            onBackPressedSupport();
            return;
        }
        LoadingDialogUtils.show(mContext);
        mPresenter.getShopInfo(shopId + "");

        nsvView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                Rect scrollRect = new Rect();
                nsvView.getHitRect(scrollRect);
                //子控件在可视范围内（至少有一个像素在可视范围内）
                if (scrollY <= cardViewPingjia.getY() && ivToTop.getVisibility() == View.VISIBLE) {//向下滚动
                    ivToTop.setVisibility(View.GONE);
                } else if (scrollY > cardViewPingjia.getY() && ivToTop.getVisibility() == View.GONE) {
                    ivToTop.setVisibility(View.VISIBLE);
                }
            }
        });

        //弹框执行动画
        float fromX = 0;
        float fromY = 1f;
        float toX = 0;
        float toY = 0;
        showAnimation = createTranslateAnimation(fromX, toX, fromY, toY);
        dismissAnimation = createTranslateAnimation(toX, fromX, toY, fromY);
    }


    /**
     * 显示评价列表
     */
    public void showPingjiaList(List<PingjiaListResponBean> pingjiaListResponBeanList) {
        if (pingjiaListResponBeanList == null || pingjiaListResponBeanList.size() == 0) {
            cardViewPingjia.setVisibility(View.GONE);
        } else {
            cardViewPingjia.setVisibility(View.VISIBLE);
            PintuanShopDetailsPjAdapter pintuanShopDetailsPjAdapter = new PintuanShopDetailsPjAdapter(R.layout.item_pintuan_shop_pingjia);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
            linearLayoutManager.setSmoothScrollbarEnabled(true);
            recyclerviewPj.setLayoutManager(linearLayoutManager);
            recyclerviewPj.setAdapter(pintuanShopDetailsPjAdapter);
            pintuanShopDetailsPjAdapter.setNewData(pingjiaListResponBeanList);
        }
    }

    ToGroupleadPopup toGroupleadPopup;
    PintuanFuwuPopup pintuanFuwuPopup;
    PintuanYoufeiPopup pintuanYoufeiPopup;
    ShareShopPopup shareShopPopup;
    PintuanBuyCantuanPopup pintuanBuyCantuanPopup;

    @OnClick({R.id.iv_back, R.id.tv_kaituan_zhuan, R.id.tv_share_zhuan, R.id.layout_fuwu_more, R.id.layout_youfei_more, R.id.iv_share_shop,
            R.id.iv_to_top, R.id.tv_look_pingjia_more, R.id.iv_kefu})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressedSupport();
                break;
            case R.id.tv_kaituan_zhuan:
                //开团赚 检测团长身份
                if (search_type == 2) {
                    if (TextUtils.isEmpty(mPintuanShopListResponBean.getGroup_id())) {
                        StyleableToast.makeText(mContext, "当前团不存在", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    this.group_id = mPintuanShopListResponBean.getGroup_id();
                    LoadingDialogUtils.show(mContext);
                    mPresenter.pticheckGroup(group_id);
                    return;
                }
                if (pintuanShopListResponBean == null) {
                    StyleableToast.makeText(mContext, "未获取到商品信息，请重试", Toast.LENGTH_SHORT, R.style.mytoast).show();
                    return;
                }
                LoadingDialogUtils.show(mContext);
                group_id = "";
                mPresenter.ptigetIdentity(pintuanShopListResponBean.getId() + "");
                break;
            case R.id.tv_share_zhuan:
                //分享赚
                mPresenter.getPtiptGoodsShare(pintuanShopListResponBean.getId() + "", mPintuanShopListResponBean == null ? "" : mPintuanShopListResponBean.getGroup_id());
                break;
            case R.id.layout_fuwu_more:
                if (pintuanFuwuPopup == null) {
                    pintuanFuwuPopup = new PintuanFuwuPopup(mContext);
                }
                pintuanFuwuPopup.setPopupGravity(Gravity.BOTTOM);
                pintuanFuwuPopup.showPopupWindow();
                break;
            case R.id.layout_youfei_more:
                if (pintuanYoufeiPopup == null) {
                    pintuanYoufeiPopup = new PintuanYoufeiPopup(mContext);
                }
                pintuanYoufeiPopup.setPopupGravity(Gravity.BOTTOM);
                pintuanYoufeiPopup.showPopupWindow();
                break;

            case R.id.iv_share_shop:
                //分享商品
                if (pintuanShopListResponBean == null) {
                    StyleableToast.makeText(mContext, "暂无分享内容", Toast.LENGTH_SHORT, R.style.mytoast).show();
                    return;
                }
                mPresenter.getPtiptGoodsShare(pintuanShopListResponBean.getId() + "", "");
                break;
            case R.id.iv_to_top:
                nsvView.fullScroll(NestedScrollView.FOCUS_UP);
                ivToTop.setVisibility(View.GONE);
                break;
            case R.id.tv_look_pingjia_more:
                //更多评价
                if (pintuanShopListResponBean == null) {
                    StyleableToast.makeText(mContext, "请重试", Toast.LENGTH_SHORT, R.style.mytoast).show();
                    return;
                }
                new StartActivityUtil(mContext, PintuanPingjiaActivity.class).putExtra(Constants.PINTUAN_SHOP_ID, pintuanShopListResponBean.getId())
                        .startActivity(true);

                break;
            case R.id.iv_kefu:
                //客服
                new StartActivityUtil(mContext, MyWebviewActivity.class).putExtra("url", Constants.WEBURL_KEFU)
                        .putExtra(Constants.WEBURL_TITLE, Constants.WEBURL_KEFU_TITLE).startActivity(true);
                break;
            default:
                break;
        }
    }

    /**
     * 显示规格弹框
     */
    public void showSpaceDialog() {
        //检测团长身份成功，可以开团
        pintuanBuyCantuanPopup = new PintuanBuyCantuanPopup(mContext, pintuanShopListResponBean, new PintuanBuyCantuanPopup.PintuanBuyCantuanCallback() {

            @Override
            public void sureClickCallback(int id, String text, String selectedPrice) {
                LoadingDialogUtils.show(mContext);
                selectedSpace = text;
                mSelectedPrice = selectedPrice;
                mPresenter.pticonfirmationOrder(pintuanShopListResponBean.getId() + "", id == -1 ? "" : (id + ""), group_id);
            }
        });
        pintuanBuyCantuanPopup.setShowAnimation(showAnimation);
        pintuanBuyCantuanPopup.setDismissAnimation(dismissAnimation);
        pintuanBuyCantuanPopup.setPopupGravity(Gravity.BOTTOM);
        pintuanBuyCantuanPopup.setClassifyOne(pintuanGoodsSpecsResponBeanList);
        pintuanBuyCantuanPopup.showPopupWindow();
    }

    private LoadImageDataThread mLoadDataThread;

    public void saveNetImageToLoacl(String downloadPath) {
        boolean isHttp = PictureMimeType.isHttp(downloadPath);
        LoadingDialogUtils.show(mContext, "保存中");
        if (isHttp) {
            mLoadDataThread = new LoadImageDataThread(downloadPath);
            mLoadDataThread.start();
        }
    }

    public class LoadImageDataThread extends Thread {
        private String path;

        public LoadImageDataThread(String path) {
            super();
            this.path = path;
        }

        @Override
        public void run() {
            try {
                showLoadingImage(path);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 下载图片保存至手机
     *
     * @param urlPath
     */
    public void showLoadingImage(String urlPath) {
        BufferedOutputStream bout = null;
        Uri outImageUri = null;
        try {
            String currentMimeType = PictureMimeType.getImageMimeType(urlPath);
            String mMimeType = PictureMimeType.isJPG(currentMimeType) ? PictureMimeType.MIME_TYPE_JPEG : currentMimeType;
            URL u = new URL(urlPath);
            String path;
            if (SdkVersionUtils.checkedAndroid_Q()) {
                outImageUri = createOutImageUri(mMimeType);
                if (outImageUri == null) {
                    mHandler.sendEmptyMessage(SAVE_IMAGE_ERROR);
                    return;
                }
                bout = new BufferedOutputStream(getContentResolver().openOutputStream(outImageUri));
                path = PictureFileUtils.getPath(this, outImageUri);
            } else {
                String suffix = PictureMimeType.getLastImgSuffix(mMimeType);
                String state = Environment.getExternalStorageState();
                File rootDir =
                        state.equals(Environment.MEDIA_MOUNTED)
                                ? Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
                                : mContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
                if (rootDir != null && !rootDir.exists() && rootDir.mkdirs()) {
                }
                File folderDir = new File(!state.equals(Environment.MEDIA_MOUNTED)
                        ? rootDir.getAbsolutePath() : rootDir.getAbsolutePath() + File.separator + "Camera" + File.separator);
                if (folderDir != null && !folderDir.exists() && folderDir.mkdirs()) {
                }
                String fileName = DateUtils.getCreateFileName("IMG_") + suffix;
                File file = new File(folderDir, fileName);
                path = file.getAbsolutePath();
                bout = new BufferedOutputStream(new FileOutputStream(path));
            }
            if (bout == null) {
                mHandler.sendEmptyMessage(SAVE_IMAGE_ERROR);
                return;
            }
            byte[] buffer = new byte[1024 * 8];
            int read;
            BufferedInputStream bin = new BufferedInputStream(u.openStream());
            while ((read = bin.read(buffer)) > -1) {
                bout.write(buffer, 0, read);
            }
            bout.flush();
            Message message = mHandler.obtainMessage();
            message.what = SAVE_IMAGE_SUCCESSFUL;
            message.obj = path;
            mHandler.sendMessage(message);
        } catch (IOException e) {
            mHandler.sendEmptyMessage(SAVE_IMAGE_ERROR);
            if (outImageUri != null) {
                getContentResolver().delete(outImageUri, null, null);
            }
            e.printStackTrace();
        } finally {
            try {
                if (bout != null) {
                    bout.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 针对Q版本创建uri
     *
     * @return
     */
    private Uri createOutImageUri(String mMimeType) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, DateUtils.getCreateFileName("IMG_"));
        contentValues.put(MediaStore.Images.Media.DATE_TAKEN, ValueOf.toString(System.currentTimeMillis()));
        contentValues.put(MediaStore.Images.Media.MIME_TYPE, mMimeType);
//        contentValues.put(MediaStore.Images.Media.RELATIVE_PATH, PictureMimeType.DCIM);

        return getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
    }

    private static final int SAVE_IMAGE_ERROR = -1;
    private static final int SAVE_IMAGE_SUCCESSFUL = 0;

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case SAVE_IMAGE_SUCCESSFUL:
                    try {
                        String path = (String) msg.obj;
                        if (!TextUtils.isEmpty(path)) {
                            if (!SdkVersionUtils.checkedAndroid_Q()) {
                                File file = new File(path);
                                MediaStore.Images.Media.insertImage(getContentResolver(), file.getAbsolutePath(), file.getName(), null);
                                new PictureMediaScannerConnection(mContext, file.getAbsolutePath(), () -> {
                                });
                            }
                            StyleableToast.makeText(mContext, "图片保存成功", R.style.mytoast).show();
                        }
                        LoadingDialogUtils.dismissDialog_ios();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case SAVE_IMAGE_ERROR:
                    ToastUtils.s(mContext, getString(R.string.picture_save_error));
                    LoadingDialogUtils.dismissDialog_ios();
                    break;
                default:
                    break;
            }
        }
    };


    @Override
    public void showContent(String list) {

    }

    @Override
    public void showMoreContent(String list) {

    }

    @Override
    public void showGoodsspecsData(List<PintuanGoodsSpecsResponBean> list) {
        LoadingDialogUtils.dismissDialog_ios();
        this.pintuanGoodsSpecsResponBeanList = list;
        showSpaceDialog();
    }

    @Override
    public void showPtigetIdentitySuccess() {
        mPresenter.getGoodsspecsData(shopId + "");
    }

    @Override
    public void showPtigetIdentityFail(int code, String msg) {
//     0=可以开团,1=不是团长身份,2=商品id为空,3=商品不存在,4=开团额度不足,5=余额不足,
        if (code == 1 || code == 4) {
            if (toGroupleadPopup == null) {
                toGroupleadPopup = new ToGroupleadPopup(mContext);
            }
            toGroupleadPopup.setPopupGravity(Gravity.BOTTOM);
            toGroupleadPopup.setPopupText(pintuanShopListResponBean);
            toGroupleadPopup.setPopupItemClickCallback(new PopupItemClickCallback() {
                @Override
                public void onSureCallback(String text) {
                    //前往首页
                    App.getInstance().finishActivity();
                    new StartActivityUtil(mContext, MainActivity.class)
                            .putExtra(Constants.TO_MAIN, Constants.MAIN_TYPE_THREE)
                            .startActivity(true);
                }

                @Override
                public void onTextChangedCallback(String text) {

                }
            });
            toGroupleadPopup.showPopupWindow();
        } else if (code == 5) {
            //余额不足
            if (customBasePopup != null) {
                customBasePopup.showPopupWindow();
                return;
            }
            customBasePopup = new CustomBasePopup(mContext, "余额不足", "\u0020去充值\u0020", "\u3000取消\u3000",
                    new CustomBasePopup.PopupWindowCallback() {
                        @Override
                        public void sureClickCallback() {
                            //去充值
                            new StartActivityUtil(mContext, WalletRechargeActivity.class).startActivity(true);
                        }

                        @Override
                        public void cancelClickCallback() {

                        }
                    });
            customBasePopup.setContentText(TextUtils.isEmpty(msg) ? "" : msg);
            customBasePopup.setPopupGravity(Gravity.CENTER);
            customBasePopup.showPopupWindow();
        } else {
            StyleableToast.makeText(mContext, TextUtils.isEmpty(msg) ? "网络加载失败" : msg, Toast.LENGTH_SHORT, R.style.mytoast).show();
        }
    }

    /**
     * 获取商品详情成功
     *
     * @param mPintuanShopListResponBean
     */
    @Override
    public void showShopInfo(PintuanShopListResponBean mPintuanShopListResponBean) {
        LoadingDialogUtils.dismissDialog_ios();
        if (mPintuanShopListResponBean == null) {
            StyleableToast.makeText(mContext, "获取商品信息失败", Toast.LENGTH_SHORT, R.style.mytoast).show();
            return;
        }
        this.pintuanShopListResponBean = mPintuanShopListResponBean;

        nowPrice.setText(pintuanShopListResponBean.getSpe_price());
        yuanPrice.setText(pintuanShopListResponBean.getYuan_price());
        yuanPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); // 设置中划线并加清晰
        tvSale.setText("已拼" + pintuanShopListResponBean.getOff_group_sum() + " 件");
        tvTitle.setText(TextUtils.isEmpty(pintuanShopListResponBean.getGoods_name()) ? "" : pintuanShopListResponBean.getGoods_name());

        initBanner();
        showPingjiaList(mPintuanShopListResponBean.getEvaluation());
        initShopDetails(mPintuanShopListResponBean.getInfo());
    }


    /**
     * 加载banner
     */
    public void initBanner() {
        List<String> mImageList = StringUtil.getStringListBySplit(pintuanShopListResponBean.getMulti_image());
        if (mImageList.size() > 0) {
            List<LocalMedia> selectList = new ArrayList<>();
            List<PintuanHomeBannerBean> bannerList = new ArrayList<>();
            for (String urlStr : mImageList) {
                selectList.add(new LocalMedia(urlStr, 1000, PictureMimeType.ofImage(), null));
                bannerList.add(new PintuanHomeBannerBean(urlStr));
            }
            rollViewPager.setBannerData(bannerList);
            //加载广告图片
            rollViewPager.loadImage(new XBanner.XBannerAdapter() {
                @Override
                public void loadBanner(XBanner banner, Object model, View view, int position) {
                    ImageView mImageView = (ImageView) view;
                    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
                    ImageLoader.load(mContext, bannerList.get(position).getImg(), mImageView);
                }
            });
            rollViewPager.setOnItemClickListener(new XBanner.OnItemClickListener() {
                @Override
                public void onItemClick(XBanner banner, Object model, View view, int position) {
                    PictureSelector.create(mContext)
                            .themeStyle(R.style.picture_default_style) // xml设置主题
                            .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)// 设置相册Activity方向，不设置默认使用系统
                            .isNotPreviewDownload(true)// 预览图片长按是否可以下载
                            .loadImageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
                            .openExternalPreview(position, selectList);
                }
            });
        }
    }

    /**
     * 加载商品详情部分  多张图片
     */
    public void initShopDetails(List<String> strList) {
        if (strList == null) {
            strList = new ArrayList<>();
        }
        recyleviewDetails.setHasFixedSize(true);
        recyleviewDetails.setNestedScrollingEnabled(false);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        PintuanShopDetailsAdapter pintuanShopDetailsAdapter = new PintuanShopDetailsAdapter(R.layout.item_pintuan_shop_details);
        recyleviewDetails.setLayoutManager(linearLayoutManager);
        recyleviewDetails.setAdapter(pintuanShopDetailsAdapter);
        pintuanShopDetailsAdapter.setNewData(strList);
    }

    @Override
    public void showPticonfirmationOrder(AddressListResponBean bean, String specsid) {
        LoadingDialogUtils.dismissDialog_ios();
        if (pintuanBuyCantuanPopup != null) {
            pintuanBuyCantuanPopup.dismiss();
        }
        if (!TextUtils.isEmpty(mSelectedPrice)) {
            if (pintuanShopListResponBean != null) {
                pintuanShopListResponBean.setSpe_price(mSelectedPrice);
            }
        }
        new StartActivityUtil(mContext, PintuanSureOrderActivity.class)
                .putExtra(Constants.PINTUAN_SURE_ORDER_INFO, pintuanShopListResponBean)
                .putExtra(Constants.PINTUAN_ADDRESS_INFO, bean)
                .putExtra(Constants.PINTUAN_SPECSID, specsid)
                .putExtra(Constants.PINTUAN_SPECS_TEXT, selectedSpace)
                .putExtra(Constants.PINTUAN_GROUP_ID, group_id)
                .startActivity(true);
    }

    /**
     * 获取分享信息成功
     *
     * @param shareResponBean
     */
    @Override
    public void showPtiptGoodsShare(ShareResponBean shareResponBean) {
        if (shareResponBean == null || TextUtils.isEmpty(shareResponBean.getShare_image())) {
            StyleableToast.makeText(mContext, "获取分享信息失败", Toast.LENGTH_SHORT, R.style.mytoast).show();
            return;
        }

        String shareText = shareResponBean.getShare_text();

        if (shareShopPopup == null) {
            shareShopPopup = new ShareShopPopup(mContext, ResaleShopDetailsActivity.this, shareText,
                    new ShareShopPopup.ItemClickCallback() {
                        @Override
                        public void saveImage(String url) {
                            if (!TextUtils.isEmpty(url)) {
                                PermissionUtil.requestPermissionForActivity(mContext, new PermissionUtil.IPermissionListener() {
                                    @Override
                                    public void permissionGranted() {
                                        saveNetImageToLoacl(url);
                                    }

                                    @Override
                                    public void permissionDenied() {
                                        StyleableToast.makeText(mContext, "权限被拒绝,请设置应用权限", Toast.LENGTH_SHORT, R.style.mytoast).show();
                                    }
                                }, "权限被拒绝,请设置应用权限", PermissionUtil.scan_permissions);
                            }
                        }
                    });
        }
        shareShopPopup.setShowAnimation(showAnimation);
        shareShopPopup.setDismissAnimation(dismissAnimation);
        shareShopPopup.setImgUrl(shareResponBean.getShare_image());
//        shareShopPopup.setImgUrl(TestBean.mUrl);
        shareShopPopup.setPopupGravity(Gravity.BOTTOM);
        shareShopPopup.showPopupWindow();

    }

    @Override
    public void pticheckGroupSuccess() {
        //可以开团
        mPresenter.getGoodsspecsData(shopId + "");
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).statusBarView(R.id.top_view)
                .statusBarDarkFont(true)
                .init();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 移除监听
        ForegroundCallbacks.get(App.getInstance()).removeListener(this);
        if (mLoadDataThread != null) {
            mHandler.removeCallbacks(mLoadDataThread);
            mLoadDataThread = null;
        }
    }

    @Override
    public void onBecameForeground() {
        Activity mActivity = App.getInstance().getCurrentActivity();
        if (mActivity == null || !(mActivity instanceof ResaleShopDetailsActivity)) {
            return;
        }
        //判断粘贴板是否存在内容
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                CharSequence mCharSequence = ClipboardUtils.getText();
                String clipboardText = TextUtils.isEmpty(mCharSequence) ? "" : mCharSequence.toString();
                if (clipboardText.length() > 0) {
                    ClipboardUtils.copyText("", "");
                    if (commonSearchPopup != null) {
                        commonSearchPopup.setContent(clipboardText);
                        commonSearchPopup.showPopupWindow();
                        return;
                    }
                    commonSearchPopup = new CommonSearchPopup(mContext,
                            new PopupItemClickCallback() {

                                @Override
                                public void onSureCallback(String text) {

                                    new StartActivityUtil(mContext, SearchShopResultActivity.class).putExtra(Constants.SEARCH_BODY,
                                            text)
                                            .startActivity(true);
                                }

                                @Override
                                public void onTextChangedCallback(String text) {

                                }
                            });
                    commonSearchPopup.setPopupGravity(Gravity.CENTER);
                    commonSearchPopup.setWidth(commonSearchPopup.getScreenWidth() * 2 / 3);
                    commonSearchPopup.setContent(clipboardText);
                    commonSearchPopup.showPopupWindow();
                }
            }
        }, 500);
    }

    @Override
    public void onBecameBackground() {

    }


}
